﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.Area;
using LJX.SmartPark.Service.Area.Recharge.Dto;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LJX.SmartPark.Service.Area.Recharge
{
    public class RechargeService : IRechargeService
    {
        private readonly IRepository<RechargeRecord> _repository;

        public RechargeService(IRepository<RechargeRecord> repository)
        {
            _repository = repository;

        }

        /// <summary>
        /// 显示分页查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<Response<List<RechargeRecord>>> GetRechargeAsync(RQuery input)
        {
            var obj = _repository.GetListQuery();
            obj = obj.WhereIf(!string.IsNullOrWhiteSpace(input.orderId), x => x.OrderId.Contains(input.orderId));
            obj = obj.WhereIf(!string.IsNullOrWhiteSpace(input.carNum), x => x.CarNum.Contains(input.carNum));
            obj = obj.WhereIf(!string.IsNullOrWhiteSpace(input.carNum), x => x.CarNum.Contains(input.carNum));
            DateTime beginDate = Convert.ToDateTime(input.beginDate); 
            DateTime endDate = Convert.ToDateTime(input.endDate);
            obj = obj.WhereIf(input.beginDate != null && input.endDate != null, x => x.OrderDate >= input.beginDate && x.OrderDate <= input.endDate);
            int total = obj.Count();
            obj = obj.Skip((input.pageIndex - 1) * input.pageSize).Take(input.pageSize);
            var result = obj.MapToList<RechargeRecord>();
            return Response<List<RechargeRecord>>.Ok(result, total);
        }
    }
}
